<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
<body>
	<div class="layui-fluid">
		<table id="yearaudit_order-table" lay-filter="yearaudit_order-table"></table>
	</div>
	<!-- 工具栏 -->
	<script type="text/html" id="toolbarYearauditOrder">
        <div class="layui-input-inline">&nbsp;联系人：</div>
        <div class="layui-input-inline">
            <input class="layui-input" id="contacts" placeholder="联系人" autocomplete="off" />
        </div>
        <div class="layui-input-inline">&nbsp;电话：</div>
        <div class="layui-input-inline">
            <input class="layui-input" id="phone" placeholder="电话" autocomplete="off" />
        </div>
        <button class="layui-btn layui-btn-normal" id="search" data-type="reload">搜索</button>
    </script>
	<!-- 操作列 -->
	<script type="text/html" id="yearaudit_order-state">
     <div class="layui-btn-group">
        <button shiro:hasPermission="yearaudit:order:edit" class="layui-btn layui-btn-sm" lay-event="edit">指派/更改</button>
    </div>
    </script>
    <script th:replace="/common/template :: script"></script>
	<script>
        var active;
		layui.use([ 'table' ], function() {
			var $ = layui.jquery;
			var table = layui.table;
			// 渲染表格
			var renderTable = function() {
				layer.load(2);
				table.render({
					elem : '#yearaudit_order-table',
					url : '/yearaudit/order/list',
					toolbar : '#toolbarYearauditOrder',
					page : true,
                    defaultToolbar: [],
					id : 'yearauditOrderReload',
					parseData:chaoLayuiTable.parseData,
					request:chaoLayuiTable.request,
					response:chaoLayuiTable.response,
					//limit : 1,
					cols : [ [
                    {
                        width : 80,
                        type: 'numbers',
                        align : 'center',
                        title : '序号',
                    },
 					{
						align : 'center',
					    field : 'shopName',
						title : '消费店铺',
					}, 
 					{
						align : 'center',
					    field : 'plate',
						title : '车牌',
					}, 
 					{
						align : 'center',
					    field : 'contacts',
						title : '联系人',
					 
					}, 
 					{
						align : 'center',
					    field : 'phone',
						title : '联系电话',
					 
					},
 					{
                        width: 400,
						align : 'center',
					    field : 'pickUpAddress',
						title : '取车地址',
					 
					},
 					{
						align : 'center',
					    field : 'remarks',
						title : '备注',
					 
					},
 					{
						align : 'center',
					    field : 'status',
						title : '状态',
                        templet: function(d){
						    var status = "";
						    if(d.status=='1'){
                                status = "已完成"
                            }else if(d.status=='2'){
                                status = "待取车"
                            }else if(d.status=='3'){
                                status = "已取车"
                            }else {
                                status = "待支付"
                            }
                            return status;
                        }
					}, 
 					{
						align : 'center',
					    field : 'createDate',
						title : '创建日期',
					 
					},
                        {
                            align : 'center',
                            field : 'takecaruser',
                            title : '取车人',

                        },
 					{
						title : '操作',
                        width : 150,
						toolbar : '#yearaudit_order-state',
						align : 'center'
					} ] ],
					done : function() {
						layer.closeAll('loading');
					}
				});

			};
			renderTable();
			// 搜索 
			active = {
				reload : function() {
					//执行重载
					table.reload('yearauditOrderReload', {
						page : {
							curr : 1
						//重新从第 1 页开始
						},
						where : {
                            contacts : $('#contacts').val(),
                            phone : $('#phone').val(),
                            status : $('#status').val()
						}
					});
				}
			};

            /**解决工具栏按钮表格重载后无效的问题**/
            $('body').on('click', '#search', function() {
                // xxxxx
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            })


			//监听工具条
			table.on('tool(yearaudit_order-table)', function(obj) {
				var data = obj.data;
				var layEvent = obj.event;
                if (layEvent === 'edit') {//指派或更改取车人
					edit(data.id,data.takecaruser);
				}
			});





			function edit(id,takecaruser) {
                var url = takecaruser?takecaruser:'';
                layer.open({
					type : 2,
					title : '指派或修改取车人',
					maxmin : true,
					shadeClose : false, // 点击遮罩关闭层
					area : [ '60%', '80%' ],
					content : '/yearaudit/order/edit?id='+ id+'&takecaruser = '+url// iframe的url
				});
			}

		});
	</script>
</body>
</html>